package cn.wolfcode.consumer_test.api._04_consume_way;

import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.PullResult;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.common.message.MessageQueue;

import java.util.List;

public class Consumer {

    public static void main(String[] args) throws Exception{
        //创建一个消费者
        DefaultMQPullConsumer defaultMQPullConsumer = new DefaultMQPullConsumer("wolfcode-consumer");
        //设置名称地址
        defaultMQPullConsumer.setNamesrvAddr("127.0.0.1:9876");
        //开启消费者
        defaultMQPullConsumer.start();
        //主动拉取消息
        PullResult pullResult = defaultMQPullConsumer.pull(new MessageQueue("04-consumer-way", "broker-a", 1), "*", 0, 10);
        List<MessageExt> msgFoundList = pullResult.getMsgFoundList();
        for (MessageExt messageExt : msgFoundList) {
            System.out.println("消息的内容是:" + new String(messageExt.getBody()));
        }

    }
}
